package isogame
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	import isogame.Event.FileLoaderEvent;
	
	public class FileLoader extends EventDispatcher{
		
		private var url:String;
		private var loader:Loader = new Loader();
		
		//---------------------------------------
		// CONSTRUCTOR
		//---------------------------------------
		public function FileLoader(url:String){
			this.url = url;
			
			var request:URLRequest = new URLRequest(url);
			
			loader.load(request);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			
		}
		
		//---------------------------------------
		// GETTER / SETTERS
		//---------------------------------------
		public function get data():Loader{
			return loader;
		}
		
		//---------------------------------------
		// PUBLIC METHODS
		//---------------------------------------
		
		
		//---------------------------------------
		// PRIVATE METHODS
		//---------------------------------------
		private function ok(event:Event):void {
			var flee:FileLoaderEvent = new FileLoaderEvent("success");
			dispatchEvent(flee);
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void {
			trace("Unable to load File: " + url);
		}
		
	}// end class
}// end package